package com.wave.traffic.NetSDKDemo;

import com.sun.jna.Pointer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class FMSGCallBack_V32 implements HCNetSDK.FMSGCallBack_V31 {

    public static volatile boolean bool = false;
    private final static Logger logger = LoggerFactory.getLogger(FMSGCallBack_V32.class);

    //报警信息回调函数
    public boolean invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
        AlarmDataHandle(lCommand, pAlarmer, pAlarmInfo, dwBufLen, pUser);
        return true;
    }

    public void AlarmDataHandle(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
        pAlarmer.read();
        logger.info("deviceIP "+new String(pAlarmer.sDeviceIP));
        logger.info(""+new String(pAlarmer.sSocketIP));
        logger.info("报警事件类型： lCommand:" + Integer.toHexString(lCommand));
        String sTime;
        String MonitoringSiteID;
        //lCommand是传的报警类型
        if(lCommand == HCNetSDK.COMM_ITS_PLATE_RESULT){
//            case HCNetSDK.COMM_ITS_PLATE_RESULT://交通抓拍结果(新报警信息)
            HCNetSDK.NET_ITS_PLATE_RESULT strItsPlateResult = new HCNetSDK.NET_ITS_PLATE_RESULT();
            strItsPlateResult.write();
            Pointer pItsPlateInfo = strItsPlateResult.getPointer();
            pItsPlateInfo.write(0, pAlarmInfo.getByteArray(0, strItsPlateResult.size()), 0, strItsPlateResult.size());
            strItsPlateResult.read();
            try {
                String sLicense = new String(strItsPlateResult.struPlateInfo.sLicense, "GBK");
                byte VehicleType = strItsPlateResult.byVehicleType;  //0-其他车辆，1-小型车，2-大型车，3- 行人触发，4- 二轮车触发，5- 三轮车触发，6- 机动车触发
                MonitoringSiteID = new String(strItsPlateResult.byMonitoringSiteID);
                logger.info("摄像头2回调车辆类型>>>>>>>>>>>>>>>>>>>>>>>>>>>"+VehicleType);
                if(VehicleType != 3 && !"无车牌\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000".equals(sLicense)){
                    bool = true;
                }else {
                    bool = false;
                }
                logger.info("车牌号：" + sLicense + ":车辆类型：" + VehicleType + ":监控点编号：" + MonitoringSiteID);
            } catch (Exception e1) {
                logger.info("AlarmDataHandle error:[{}]",e1.getMessage(),e1);
            }
        }
    }

    public static boolean isVehicle(){
        return bool;
    }

    public static void resetVehicle(){
        bool= false;
    }

}